package com.open.validator.impl;

import com.open.validator.EnumExt;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;

/**
 * @author: system
 * @Date: 2024/4/19 15:10
 * @Version: V1.0
 * @description: desc:
 */

public class EnumExtValidator implements ConstraintValidator<EnumExt, CharSequence> {

    private String[] values;

    @Override
    public void initialize(EnumExt parameters) {
        values = parameters.value();
    }

    @Override
    public boolean isValid(CharSequence value, ConstraintValidatorContext context) {
        if (value == null || values.length == 0) {
            return true;
        }
        return Arrays.asList(values).contains(value.toString());
    }

}
